library(tidyverse)
fish <- read.csv("BlackfootFish.csv")Error in file(file, "rt"): cannot open the connection
Functions + Fish
This is a continuation of Lab 7: Functions + Fish.
library(tidyverse)
fish <- read.csv("BlackfootFish.csv")Error in file(file, "rt"): cannot open the connection
A frequently used measurement for fish health is a condition index (Wikipedia article). The following simple equation can be used to calculate the approximate condition index of a fish:
\[\text{condition index} = \frac{weight}{length^3} \times 100\]
1. There are specific units required for the calculation of a condition index – length must be in centimeters and weight must be in grams. The weight data for the Blackfoot River fish were collected in grams; the length data were collected in millimeters. Transform the length data to the correct units.
# Code for 12. Replace impossible length and weight measurements with NAs. Do some research on the 4 species of trout included in these data to determine what measurements are unlikely or impossible. Write a function to handle this process.
Your function should accept at least three inputs:
If a value falls outside these bounds, you should replace it with an NA.
If you are struggling with the structure of your function, I would suggest reading the Mutating Function from R4DS.
Use your function to modify the length and weight columns of the BlackfootFish data set, removing values you believe are unreasonable.
# Code for 23. Write a function to calculate the condition index of a fish, given inputs of weight and length.
Consider whether your function will accept vectors as inputs or if it will accept variable names as inputs!
# Code for 34. Make a thoughtful visualization of how fish conditions have varied over the duration of this study.
# Code for 4